home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5321 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  70 lines

  1. Path: tank.news.pipex.net!pipex!demon!zace.compulink.co.uk
  2. From: chris@zace.compulink.co.uk (Chris)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help on this C++ v1 program
  5. Date: Sat, 03 Feb 1996 18:51:35 GMT
  6. Message-ID: <31126397.2406958@PUBNEWS.DEMON.CO.UK>
  7. NNTP-Posting-Host: zace.compulink.co.uk
  8. X-NNTP-Posting-Host: zace.compulink.co.uk
  9. X-Newsreader: Forte Agent .99c/16.141
  10.  
  11. Can anyone spot the problem that I am getting, and tell me where and
  12. why I am going wrong.
  13.  
  14. The idea of this program is to put a line number at the start of each
  15. line of your files.  (For those of you that have read it, yes, this
  16. code comes from Learn C in 21 days!)
  17. -----------------------------------------------------------------------------------------------------------
  18.  
  19. #include <stdio.h>        
  20. #include <process.h>
  21.  
  22. void do_heading(char *filename);
  23.  
  24. int line, page;
  25.  
  26. main( int argv, char *argc[] )
  27. {
  28.     char buffer[256];
  29.     FILE *fp;
  30.     
  31.     if( argv <2)
  32.     {
  33.         fprintf(stderr, "\nProper Usage is : " );
  34.         fprintf(stderr, "\n\nPRINT_IT filename.ext\n" );
  35.         exit(1);
  36.     }
  37.     
  38.     if (( fp = fopen( argc[1], "r" )) == NULL )
  39.     {
  40.         fprintf(stderr, "Error opening file, %s!", argc[1]);
  41.         exit(1);
  42.     }
  43.     
  44.     page = 0;
  45.     line = 1;
  46.     do_heading( argc[1]);
  47.     
  48.     while( fgets( buffer, 256, fp ) !=NULL )
  49.     {    
  50.         if( line % 55 == 0)
  51.             do_heading( argc[1] );
  52.             fprintf(_stdprn, "%4d:\t%s", line++, buffer );
  53.     }
  54.     
  55.     fprintf(_stdprn, "\f" );
  56.     fclose(fp);
  57.     return 0;
  58.     
  59. }   
  60.  
  61. void do_heading( char *filename)
  62. {
  63.     page++;
  64.     if (page >1)
  65.         fprintf(_stdprn,"\f");
  66.     fprintf(_stdprn, "Page: %d, %s\n\n", page, filename);
  67. }
  68.  
  69.  
  70.